<?php


namespace app\admin\controller;


use think\Controller;
use think\Db;
use think\Request;

class Login extends Controller
{
    public function index()
    {
        return $this->fetch();
    }


    public function login(Request $request)
    {
        $data = $request->param();
        $result = Db::table('user')->where('user_name',$data['username'])->find();
        if (!empty($result)) {
            if ($data['password'] == $result['password']){
                $loginTime = ['last_login_time'=>time()];
                Db::table('user')->where("user_name",$data['username'])->update($loginTime);
                return json(['code'=>1,'msg'=>'登入成功']);
            } else {
                return json(['code'=>505,'msg'=>'密码错误']);
            }
        } else {
            return json(['code'=>404,'msg'=>'用户不存在']);
        }
    }
}